package cn.mesmile.juc.thread;

import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ConcurrencyTester;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;

/**
 * @author zb
 * @date 2021/8/18 11:00
 * @Description 并发测试
 */
public class ThreadTest {

    public static void main(String[] args) {
        // 测试 100 个并发
        ConcurrencyTester tester = ThreadUtil.concurrencyTest(100, () -> {
            // 测试的逻辑内容
            long delay = RandomUtil.randomLong(10, 200);
            ThreadUtil.sleep(delay);
            Console.log("{} test finished, delay: {}", Thread.currentThread().getName(), delay);
        });

        // 获取总的执行时间，单位毫秒
        Console.log("并发花费时间为："+tester.getInterval());
    }
}
